//
//  AIGirlDiscoverCollectionViewCell.swift
//  AIGirl
//
//  Created by Rae on 2023/12/28.
//

import UIKit



class AIGirlDiscoverCateItem: UICollectionViewCell {
    
    private var titleButton = UIButton(type: .custom)//UIIconButton(style: .leading(itemSpace: 5))
    var model: AIGirlDiscoverCateModel? {
        didSet{
            guard let md = model else { return }
            titleButton.setTitle(md.title, for: .normal)
            if md.imgStr.count > 0 {
                titleButton.setImage(md.imgStr.toImage, for: .normal)
                titleButton.setImage(md.selImgStr.toImage, for: .selected)
            }else{
                titleButton.setImage("".toImage, for: .normal)
                titleButton.setImage("".toImage, for: .selected)
            }
            if md.title == "VIP" {
                if md.select {
                    self.fj.gradientColors(.leftToRight(["#DC9A46".toColor,"#D8BF78".toColor]))
                }else{
                    self.fj.gradientColors(.leftToRight(["#F2F2FD".toColor.alpha(0.2),"#F2F2FD".toColor.alpha(0.2)]))
                    self.backgroundColor = "#F2F2FD".toColor.alpha(0.2)
                }
            }else{
                self.fj.gradientColors(.leftToRight(["#F2F2FD".toColor.alpha(0.2),"#F2F2FD".toColor.alpha(0.2)]))
                if md.select{
                    self.backgroundColor = "#7F58FF".toColor
                }else{
                    self.backgroundColor = "#F2F2FD".toColor.alpha(0.2)
                }
            }
            titleButton.isSelected = md.select
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = "#F2F2FD".toColor.alpha(0.2)
        self.layer.cornerRadius = 15
        self.layer.masksToBounds = true
        
        contentView.subviews {
            titleButton
        }

        titleButton.fillContainer()
        
        titleButton.style { v in
//            v.iconSize = CGSize(width: 12, height: 11)
            v.setTitleColor("#B6AFC4".toColor, for: .normal)
            v.setTitleColor(.white, for: .selected)
            v.titleLabel?.font = 14.font_regular
            v.isUserInteractionEnabled = false
            v.contentHorizontalAlignment = .center
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

class AIGirlDiscoverItem: UICollectionViewCell {
    
    private let iconImageView = c_make_ex(UIImageView.self)
        .corner(17).mode(.scaleAspectFill).end()
    private let borderImageView = c_make_ex(UIImageView.self)
        .image("AIGirl_Discover_border").end()
    private let likeImageView = c_make_ex(UIImageView.self)
        .image("AIGirl_Discover_like").end()
    private let likeLabel = c_make_ex(UILabel.self)
        .color(.white).font(15.font_bold).end()
    private let preImageView = c_make_ex(UIImageView.self)
        .image("AIGirl_Discover_preLight").end()
    
    var model:AIGirlItemModel?{
        didSet{
            guard let md = model else { return }
            iconImageView.loadImage(url: md.image)
            if md.initCollect > 0 {
                likeImageView.isHidden = false
                likeLabel.text = String(md.initCollect)
            }else{
                likeImageView.isHidden = true
                likeLabel.text = ""
            }
            preImageView.isHidden = !(md.isVip == 1)
            borderImageView.isHidden = !(md.isVip == 1)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = .clear
        
        contentView.subviews {
            iconImageView.subviews{
                likeImageView
                likeLabel
                preImageView
                borderImageView
            }
        }

        iconImageView.fillContainer()
        borderImageView.fillContainer()
        likeImageView.leading(10).bottom(6.5).size(26)
        likeLabel.leading(43)
        likeLabel.CenterY == likeImageView.CenterY
        preImageView.bottom(16.5).trailing(12.5).width(20).height(15)
        preImageView.isHidden = true
        borderImageView.isHidden = true
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
